﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.District
{
    public class DistrictPresenter : Presenter<IDistrictView>
    {
        public DistrictPresenter(IDistrictView view)
            : base(view)
        {
        }

        public void Display(string districtCode)
        {
            if (districtCode == null) return;

            var district = Model.GetDistrict(districtCode);

            View.DistrictCode = district.DistrictCode;
            View.DistrictName = district.DistrictName;
            View.CreateDate = district.CreateDate;
            View.ModifiedDate = district.ModifiedDate;
            View.Description = district.Description;
            View.IsActive = district.IsActive;
        }

        public int Save(bool action)
        {
            var district = new DistrictModel
            {
                DistrictCode = View.DistrictCode,
                DistrictName = View.DistrictName,
                CreateDate = View.CreateDate,
                ModifiedDate = View.ModifiedDate,
                Description = View.Description,
                IsActive = View.IsActive
            };

            if (action == true)
                return Model.AddDistrict(district);
            else
                return Model.UpdateDistrict(district);
        }

        public int Delete(string districtCode)
        {
            return Model.DeleteDistrict(districtCode);
        }
    }
}
